<template>
  <view class="container" :style="appThemeStyle">
    <!-- 标题 -->
    <view class="page-title">需求信息</view>
    <!-- 表单组件 -->
    <view class="form-wrapper">
      <u-form :model="form" ref="uForm" label-width="140rpx">
        <u-form-item label="标题" prop="title">
          <u-input v-model="form.title" placeholder="请输入标题" />
        </u-form-item>
        <u-form-item label="内容" prop="content">
          <u-input type="textarea" v-model="form.content" placeholder="请输入需求信息" />
        </u-form-item>
        
      </u-form>
    </view>
    <!-- 操作按钮 -->
    <view class="footer">
      <view class="btn-wrapper">
        <view class="btn-item btn-item-main" :class="{ disabled }" @click="handleSubmit()">提交</view>
      </view>
    </view>
  </view>
</template>

<script>
 
  import * as AddressApi from '@/api/address'

  // 表单验证规则
  const rules = {
    title: [{
      required: true,
      message: '请输入标题',
      trigger: ['blur', 'change']
    }],
    content: [{
      required: true,
      message: '请输入需求信息',
      trigger: ['blur', 'change']
    }],
   
  }

  export default {
    
    data() {
      return {
        form: {
          content: '',
          title: '',          
        },
        rules,
        // 按钮禁用
        disabled: false
      }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
		
	},

    // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
    onReady() {
      this.$refs.uForm.setRules(this.rules)
    },

    methods: {

      
      handleSubmit() {
        const app = this
        if (app.disabled) {
          return false
        }
		console.log(app.form);
        app.$refs.uForm.validate(valid => {
          if (valid) {
            app.disabled = true
            AddressApi.submit(app.form)
              .then(result => {
				  
				if(result.status == '200'){
					app.$toast('感谢您的反馈');
					setTimeout(function(){
						uni.navigateBack()
					},1500)
				}else{
					app.$toast(result.message)
				}
                
                
              })
              .finally(() => app.disabled = false)
          }
        })
      }

    }
  }
</script>

<style>
  page {
    background: #f7f8fa;
  }
</style>
<style lang="scss" scoped>
  .page-title {
    width: 94%;
    margin: 0 auto;
    padding-top: 40rpx;
    font-size: 28rpx;
    color: rgba(69, 90, 100, 0.6);
  }

  .form-wrapper {
    margin: 20rpx auto 20rpx auto;
    padding: 0 40rpx;
    width: 94%;
    box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
    border-radius: 16rpx;
    background: #fff;
  }

  // 底部操作栏
  .footer {
    margin-top: 80rpx;

    .btn-wrapper {
      height: 100%;
      // display: flex;
      // align-items: center;
      padding: 0 20rpx;
    }

    .btn-item {
      flex: 1;
      font-size: 28rpx;
      height: 86rpx;
      color: #fff;
      border-radius: 50rpx;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .btn-item-wechat {
      background: #0ba90b;
      margin-bottom: 26rpx;
    }

    .btn-item-main {
      background: linear-gradient(to right, $main-bg, $main-bg2);
      color: $main-text;

      // 禁用按钮
      &.disabled {
        opacity: 0.6;
      }
    }

  }
</style>